package com.zdya.combatdocuments.controller;

import com.zdya.combatdocuments.entity.vo.DocumentVO;
import com.zdya.combatdocuments.entity.vo.ResultEnum;
import com.zdya.combatdocuments.entity.vo.ResultVo;
import com.zdya.combatdocuments.entity.vo.UserChatVO;
import com.zdya.combatdocuments.service.UserChatService;
import com.zdya.combatdocuments.util.ResultVoUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


/**
 * @author bj
 * @date 23/6/1
 * @desc 用户聊天
 */
@RestController
@RequestMapping("/documents/userChat")
public class UserChatController {

    @Autowired
    private UserChatService userChatService;

    /**
     * @desc 发送文件
     * @param multipartFile
     * @param userChatVO
     * @return
     */
    @ApiOperation("发送消息")
    @PostMapping(value = "/sendMsg")
    public ResultVo<UserChatVO> sendMsg(@RequestParam("file") MultipartFile multipartFile, UserChatVO userChatVO){
        return ResultVoUtil.success(userChatService.sendMsg(multipartFile, userChatVO));
    }

    // 呈报接口
    @ApiOperation("呈报接口")
    @PostMapping("/declareDoc")
    public ResultVo declareDoc(@RequestParam("file") MultipartFile multipartFile, UserChatVO userChat) {
        return ResultVoUtil.success(userChatService.declareDoc(multipartFile, userChat));
    }

    // 审批
    @ApiOperation("审批接口")
    @PostMapping("/approveDoc")
    public ResultVo approveDoc(@RequestBody UserChatVO userChat) {
        return ResultVoUtil.success(userChatService.approveDoc(userChat));
    }

    /**
     * @desc 查询文书详情
     * @param documentVO 前端传参
     * @return
     */
    @GetMapping("/viewDocDetail")
    public ResultVo viewDocDetail(DocumentVO documentVO) {
        DocumentVO document = userChatService.viewDocDetail(documentVO);
        return ResultVoUtil.success(document);
    }

    /**
     * @desc 查询聊天记录
     * @param userChatVO 前端传参
     * @return
     */
    @PostMapping("/queryUserChats")
    public ResultVo queryUserChats(@RequestBody UserChatVO userChatVO) {
        return ResultVoUtil.success(userChatService.queryUserChats(userChatVO));
    }

    /**
     * 文书审批结束状态更新
     */
    @GetMapping("/updateDocEndStatus")
    public ResultVo updateDocEndStatus(@RequestParam("chatId") Long chatId, @RequestParam("docId") Long docId) {
        userChatService.updateDocEndStatus(chatId, docId);
        return ResultVoUtil.success(ResultEnum.SUCCESS.getMessage());
    }

    /**
     * 转发文书
     * @param userChatVO
     * @return
     */
    @PostMapping("/docForward")
    public ResultVo docForward(@RequestBody UserChatVO userChatVO) {
        return ResultVoUtil.success(userChatService.docForward(userChatVO));
    }
}
